package com.dckeji.shiplock.webapp.dao.impl;

import com.dckeji.shiplock.webapp.dao.ITimeOutApplyDao;
import com.dckeji.shiplock.webapp.pojo.TimeOutApply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: TianWei
 * Date: 2017/8/9
 * Time: 11:48
 */
@Repository
public class TimeOutApplyDaoImpl implements ITimeOutApplyDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int timeOutApply(TimeOutApply timeOutApply) {
        String sql = "INSERT INTO timeoutapply(timeOutType,timeOutShipNo,timeOutDesc,timeOutVocherUrls,commitTime) VALUES(?,?,?,?,?)";

        return jdbcTemplate.update(sql, new Object[]{timeOutApply.getTimeOutType(), timeOutApply.getTimeOutShipNo(),
                timeOutApply.getTimeOutDesc(), timeOutApply.getTimeOutVocherUrls(), timeOutApply.getCommitTime()});
    }

    @Override
    public List<TimeOutApply> queryTimeOutApplyList() {
        String sql = "select timeOutApplyId,timeOutType,timeOutShipNo,timeOutDesc,timeOutVocherUrls,commitTime from timeoutapply WHERE isExamine=0";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<TimeOutApply>(TimeOutApply.class));
    }
}
